package com.common.utils.regular;

import jdk.nashorn.internal.runtime.regexp.joni.Regex;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author xin.ding
 * @date 2020/10/21 18:35
 */
public class Test {




    public static void main(String[] args) {
        testtest();
    }

    private void test(){
        String str = "select * from order where createdUser = ${currentUser} and  depart = ${currentOrg} and status = 'VALID'";
        String reg = "\\$\\{[a-zA-Z0-9]+\\}";

        Pattern patten = Pattern.compile(reg);
        Matcher matcher = patten.matcher(str);
        List<String> matchStrs = new ArrayList<>();

        //此处find（）每次被调用后，会偏移到下一个匹配
        while (matcher.find()) {
            //获取当前匹配的值
            matchStrs.add(matcher.group());
        }

        for (int i = 0; i < matchStrs.size(); i++) {
            System.out.println(matchStrs.get(i));
        }
    }



    public static void testtest() {
        String test = "hahahhehe sendCode\":\"12367890123rsdfsdfsdfdsahahhehe sendCode\":\"12367890123rsdfsdfsdfds";
        test = regMatch(test, "sendCode\":\"([\\d]{8})([\\d]{3})");

    }




    public static String regMatch(String withinText, String regString) {
        String code = null;
        Pattern pattern = Pattern.compile(regString);
        Matcher matcher = pattern.matcher(withinText);
        if (matcher.find()) {
            matcher.reset();
            while (matcher.find()) {
                code = matcher.group(1);
                System.err.println("aaaa" + code);
                code = matcher.group(0);
                System.err.println("bbbb" + code);
                code = matcher.group(2);
                System.err.println("ccc" + code);
            }
        }
        return code;
    }

}
